# -*- coding: UTF-8 -*-
import time
import os

print("陈哲");
a = 100
b = 100.0
c = "lumia"
str = "hello world"  # 字符串
list = ("a", "b", 1, 2, "mammm")  # 元祖
dic = {'a1': 'b1', 'a2': 'b2', 'a3': 'b4', 'a4': 'b4', 'a5': 'b5'}
print(a)
print(b)
print(c)
print(str[2])
print(str[2:])
print(str[2:5])
print(str * 2)
print(dic['a1'])
print(dic.keys())
print(dic.values())

name = 'python'
if name == 'python':
    print("success")
else:
    print("fail")

# for letter in 'infoq':
#    print(letter)

fruits = ['apple', 'banana', 'pear', 'orange']
for fruit in fruits:
    print("当前水果：" + fruit)
for index in range(len(fruits)):
    print("当前水果:" + fruits[index])

print(time.asctime(time.localtime(time.time())))
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))


# 定义函数
def printme(str):
    print(str);
    return 3;


s = printme("sb");
print(s);


def test2(str, *str2):
    print("第一个参数:" + str);
    for var in str2:
        print("第二个参数：" + var);
    return;


test2("测试", "哈尼", "wolf", "shit", "bitch");

# lambda表达式
sum = lambda a, b: a + b;
print(sum(1, 2));

print(globals());  # 返回所有的全局变量
print(locals());  # 返回所有的局部变量
# input函数
# inputcontent=input("请输入：");
# print("请输入的内容是:"+inputcontent);

# 文件读写

# print(fo.name)
# print(fo.mode)

try:
    fo = open("/Users/lumia/Desktop/python.txt", "a+");
    fo.write("http://www.baidu.com");
finally:
    fo.close();

    try:
        fo1 = open("/Users/lumia/Desktop/python.txt", "r+");
        read1 = fo1.read();
        print(read1);
    finally:
        fo1.close();

os.rename("C:/Users/HANZHI-tanglin/Desktop/python.txt", "C:/Users/HANZHI-tanglin/Desktop/python2.txt");
os.remove("C:/Users/HANZHI-tanglin/Desktop/python.txt");
os.mkdir("/Users/lumia/Desktop/python");
os.rmdir("/Users/lumia/Desktop/python");
try:
    fh = open("testfile", "w");
    fh.write("这是一个测试文件，用于测试异常!!");
except IOError:
    print("Error: 没有找到文件或读取文件失败");
else:
    print("内容写入文件成功");
    fh.close()
